<?php

namespace app\admin\model\chient;

use think\Model;


class Index extends Model
{

    

    

    // 表名
    protected $name = 'aa_client';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'types_text',
        'c_sex_text',
        'm_sex_text',
        'time_text',
        'ctypes_text',
        'ctypestime_text'
    ];
    

    
    public function getTypesList()
    {
        return ['1' => __('Types 1'), '0' => __('Types 0')];
    }

    public function getCSexList()
    {
        return ['1' => __('C_sex 1'), '0' => __('C_sex 0')];
    }

    public function getMSexList()
    {
        return ['1' => __('M_sex 1'), '0' => __('M_sex 0')];
    }

    public function getCtypesList()
    {
        return ['1' => __('Ctypes 1'), '2' => __('Ctypes 2'), '3' => __('Ctypes 3')];
    }


    public function getTypesTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['types']) ? $data['types'] : '');
        $list = $this->getTypesList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['c_sex']) ? $data['c_sex'] : '');
        $list = $this->getCSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getMSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['m_sex']) ? $data['m_sex'] : '');
        $list = $this->getMSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['time']) ? $data['time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getCtypesTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ctypes']) ? $data['ctypes'] : '');
        $list = $this->getCtypesList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCtypestimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ctypestime']) ? $data['ctypestime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCtypestimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function quyu()
    {
        return $this->belongsTo('app\admin\model\aa\Quyu', 'quyu_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
